package com.lsh.controller;

import com.lsh.common.HealthMobileException;
import com.lsh.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常捕获
 */
@RestControllerAdvice
public class HealthMobileExceptionAdvice {
    @ExceptionHandler(HealthMobileException.class)
    public Result handleHealthException(HealthMobileException e){
        return new Result(false,e.getMessage());
    }

    /**
     * 发生未知的错误(非自己定义的错误)
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e){
        e.printStackTrace();
        return new Result(false,"未知错误，请联系管理员");
    }
}
